﻿@using KRM.Core
@model PageModel
@{
    ViewBag.Title = "Page";
    Layout = "~/Views/Shared/_Layout.cshtml";

    List<tblPermissionPage> lstPages = ViewBag.lstPages;

    var page = Request.QueryString["p"] != null ? Convert.ToInt32(Request.QueryString["p"]) : 1;

    var itemPerPage = 20;
    var pagingCount = Convert.ToInt32(Math.Ceiling((lstPages.Count / (float)itemPerPage)));
    var listPaging = lstPages.Skip((page - 1) * itemPerPage).Take(itemPerPage).ToList();
}

<div class="container-fluid">
    <div class="box">
    <div class="box-title">
        <h3><i class="icon-edit"></i>Page</h3>
    </div>
    <div class="box-content">
        @if (!string.IsNullOrEmpty(ViewBag.msg) && ViewBag.msg == "success")
        {
            <div class="alert alert-success">
                <button type="button" class="close" data-dismiss="alert">×</button>
                <strong>Success!</strong>
            </div>
        }
        @using (Html.BeginForm("Page", "Permission", FormMethod.Post, new { @class = "form-horizontal" }))
        {
            <div class="control-group">
                <label class="control-label" for="TypePageId">Type page</label>
                <div class="controls">
                    @Html.DropDownList("TypePageId")
                    @Html.ValidationMessageFor(model => model.TypePageId)
                </div>
            </div>
            <div class="control-group">
                <label class="control-label" for="Name">Name</label>
                <div class="controls">
                    @Html.EditorFor(model => model.Name, new { required = "required" })
                    @Html.ValidationMessageFor(model => model.Name)
                </div>
            </div>
            <div class="control-group">
                <label class="control-label" for="Url">Url</label>
                <div class="controls">
                    @Html.EditorFor(model => model.Url, new { required = "required" })
                    @Html.ValidationMessageFor(model => model.Url)
                </div>
            </div>
            <div class="form-actions">
                <button type="submit" class="btn btn-primary">Create</button>
            </div>
        }
    </div>
    

    <div class="row-fluid">
        <table class="table table-hover table-bordered table-fix">
            <thead>
                <tr>
                    <th>ID</th>
                    <th>Name</th>
                    <th>Url</th>
                    <th>Type page</th>
                    <th>Action</th>
                </tr>
            </thead>
            <tbody>
                @foreach (var item in listPaging)
                {
                    <tr>
                        <td>
                            @item.Id
                        </td>
                        <td><a href="/permission/editpage/@item.Id">@item.Name</a></td>
                        <td>@item.Url</td>
                        <td>@item.tblPermissionTypePage.Name</td>
                        <td><a href="/permission/deletepage/@item.Id" onclick="javascript:return confirm('Are you sure?');">Delete</a></td>
                    </tr>
                }
            </tbody>
        </table>
        @if (pagingCount > 1)
        {
            <div class="paging">
                <a href="/permission/page">«</a>
                <span>
                    @for (int j = page - 3; j <= page + 3; j++)
                    {
                        if (j > 0 && j <= pagingCount)
                        {
                            if (j == page)
                            {
                                <a href="/permission/page?p=@j" class="page-active">@j</a>
                            }
                            else
                            {
                                <a href="/permission/page?p=@j">@j</a>
                            }

                        }
                    }
                </span>
                <a href="/permission/page?p=@pagingCount">»</a>
            </div>
        }
    </div>
</div>
</div>

